package com.tencreat.mall.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.entity.SysDictData;
import com.tencreat.common.core.domain.model.IdAndPage;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.page.TableDataInfo;
import com.tencreat.common.utils.StringUtils;
import com.tencreat.domain.account.MallRegion;
import com.tencreat.domain.account.MallStore;
import com.tencreat.domain.mall.MallConsult;
import com.tencreat.domain.mall.dto.MallGoodsSearchDTO;
import com.tencreat.domain.mall.vo.*;
import com.tencreat.domain.mall.dto.*;
import com.tencreat.mapper.mall.MallGoodsKillMapper;
import com.tencreat.service.account.IMallRegionService;
import com.tencreat.service.account.IMallStoreService;
import com.tencreat.service.mall.*;
import com.tencreat.service.system.ISysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * 描述信息
 *
 * @Author lx
 * @Company: 深圳腾创互联科技有限公司
 * @link: https://tencreat.com
 * @Date: 2022/8/16 0016 10:15
 */
@Slf4j
@RequestMapping("/api/index")
@Api(tags = "1-首页接口")
@RestController
public class ApiIndexController extends BaseController {
    @Autowired
    private IMallLunboService mallLunboService;

    @Autowired
    private ISysDictDataService dictDataService;

    @Autowired
    private IMallGoodsService mallGoodsService;


    @Autowired
    private IMallStoreService mallStoreService;//店铺

    @Autowired
    private IMallRegionService mallRegionService;//地图


    @ApiOperation(value = "获取轮播图")
    @PostMapping("/lunbo/list")
    public HttpResult<List<MallLunboVO>> getLunbo(Integer type) {
        return mallLunboService.getList(type);
    }


    @ApiOperation(value = " 商品列表 集成 搜索 推荐商品")
    @PostMapping("/goods/list")
    public HttpResult<IPage<MallGoodsListVO>> list(@RequestBody MallGoodsSearchDTO mallGoodsSearchPo) {
        return HttpResult.ok(mallGoodsService.apiList(mallGoodsSearchPo));
    }


    @ApiOperation(value = "查询店铺商家列表 ")
    @PostMapping("/list")
    HttpResult<IPage<MallGoodsListVO>> list2(@RequestBody MallGoodsSearchDTO mallStore) {
        IPage<MallStore> iPage = new Page<>(mallStore.getPageNum(), mallStore.getPageSize());
        return HttpResult.ok(mallStoreService.page(iPage, mallStore));
    }


    /**
     * 描述信息  首页扫码,根据商户id跳转
     *
     * @Author yaoruiqi
     * @Date: 2023/10/10 06:57
     */
    @ApiOperation(value = "首页扫码,根据商户id跳转")
    //@GetMapping("/code/{id}")
    public HttpResult<MallStoreScanInfoVO> storeCode(@PathVariable Long id) {
        return HttpResult.ok(mallStoreService.selectScanMallStoreById(id));
    }


    @ApiOperation(value = "查询地图列表")
    @PostMapping("/regionList")
    HttpResult<Map<String, List<MallRegion>>> regionList(@RequestBody MallRegion mallRegion) {
        return HttpResult.ok(mallRegionService.regionList(mallRegion));
    }

}
